package kr.or.kead.ui.meun;

import java.awt.event.ActionEvent;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import kr.or.kead.domain.Depart;
import kr.or.kead.domain.Professor;
import kr.or.kead.service.DaoProfessor;
import kr.or.kead.service.Daodepart;
import kr.or.kead.ui.insert_update.DepartInsrtUpdate;
import kr.or.kead.ui.insert_update.ProfessorUpdate;
import kr.or.kead.ui.list.AbsTableList;
import kr.or.kead.ui.list.DepartTableList;
import kr.or.kead.ui.list.ProfessorTableList;

public class ProfessorMenu extends AbsMeun {
	
	private DaoProfessor daoProfessor;
	private AbsTableList atl;
	
	public ProfessorMenu(JFrame frame, int height) {
		super(frame, "교수 관리");
		atl = new ProfessorTableList(height);
		daoProfessor = new DaoProfessor();
	}

	@Override
	protected void addMenuActionPerformed(ActionEvent e) {
		ProfessorUpdate insert = new ProfessorUpdate(null);
		insert.setVisible(true);
		if (insert.showDialog()==0)atl.setTableModel();

	}

	@Override
	protected void delMenuActionPerformed(ActionEvent e) {
		int res = searchNum(daoProfessor, "삭제",0);
		if (res !=-1 && daoProfessor.deleteDao(res) != -1){
			atl.setTableModel();
			JOptionPane.showMessageDialog(null, "삭제 되었습니다");
		}

	}

	@Override
	protected void updateMenuActionPerformed(ActionEvent e) {
		int res = searchNum(daoProfessor, "수정",0);
		if (res !=-1){
			Professor professor = (Professor)daoProfessor.selectTableById(res);
			ProfessorUpdate update = new ProfessorUpdate(professor);
			update.setVisible(true);
			
			if (update.showDialog()==0)atl.setTableModel();
		}

	}

	@Override
	protected void listMenuActionPerformed(ActionEvent e) {
		refreshList(atl);

	}

}
